package com.commonEncryptionAlgorithms.dissymmetry.rsa;

import org.junit.Test;

import java.security.PrivateKey;
import java.security.PublicKey;

public class Run {

    @Test
    public void encrypt() throws Exception {
        // 要加密的数据
        String originalData = "Hello, World!";
        PublicKey publicKey = RSAUtil.getPublicKey("public_key.pem");

        // 加密数据
        String encrypt = RSAUtil.encrypt(originalData, publicKey);
        System.out.println("Encrypted Data: \n" + encrypt);
    }

    @Test
    public void decrypt() throws Exception {
        String str = "cAwlLJbfau9JLeEfFX2tVf+OFhGhCllCf4aLTvxvRrJuIWN4/qyBY53jIINj+ronKHA2ARf2z0v93g0/wZTcydq9AUPvQbPbe/pkaErE+aRV94Yg7Fmu8Uxq6S6TwlRjhGiJRxmsAPPFh6ZhTJ+hOOwHp7B6AOFDOwlTmdvaVHhxeGyTbB/i8hR5iIMiA1C1VLf3+zh8D6zBVHEOhzdCAo32/Ht6ZWscMSQsX1ktjbUgxtpiaeH6699nsqNJ7gdjwoeS8bADYH0JpxLe6U+cYuj4m68ZeF5GJcbeSracGk7fLscTJf/ZbgKt0r6lGnNwLYIL3xeR4S64eSvOuLrWmA==";
        PrivateKey privateKey = RSAUtil.getPrivateKey("private_key.pem");
        String decrypt = RSAUtil.decrypt(str, privateKey);
        System.out.println(decrypt);
    }
}
